package org.lease.web.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.lease.common.result.Result;
import org.lease.model.entity.UserInfo;
import org.lease.model.req.AppUserLoginRequest;
import org.lease.service.LoginService;
import org.lease.web.service.AppLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "登录管理")
@RestController
@RequestMapping("/app/login")
public class LoginController {
    @Autowired
    private AppLoginService loginService;

    @Operation(summary = "获取短信验证码")
    @GetMapping("/getCode")
    public Result getSMS(String phone) {
        loginService.sendSMSCode(phone);
        return Result.success();
    }

    @Operation(summary = "手机号登录")
    @PostMapping("/login")
    public Result<String> login(@RequestBody AppUserLoginRequest request) {
        String token = loginService.login(request);
        return Result.success(token);
    }

    @Operation(summary = "获取当前登录用户信息")
    @GetMapping("/info")
    public Result<UserInfo> getInfo() {
        UserInfo userInfo = loginService.getUserInfo();
        return Result.success(userInfo);
    }
}
